from sklearn.model_selection import GridSearchCV

parameters = {'n_estimators': [5, 10, 20], 'max_depth': [2, 3, 4, 5, 6], 'min_samples_leaf': [5, 10, 20, 30]}
new_model = RandomForestClassifier(random_state=123)
grid_search = GridSearchCV(new_model, parameters, cv=6, scoring='accuracy')
grid_search.fit(X_train, y_train)
grid_search.best_params_

# 输出
# {'max_depth': 5, 'min_samples_leaf': 20, 'n_estimators': 5}